import DrawnStep from "../DrawnStep/DrawnStep";

export default class BasePainting {
    constructor() {
        this.painter = undefined;
    }

    beDrawn(painter) {
        if (this.drawnStep) {
            this.updateDrawnStep();
            painter.drawingFollowStep(this.drawnStep);
        }
    }

    setPainter(painter) {
        this.painter = painter;
        this.onPainterLoaded(painter);
    }

    /**
     * @param step {function}
     */
    activeDrawnStep(step) {
        this.drawnStep = new DrawnStep(this.exportDrawnData.bind(this), step);
    }

    updateDrawnStep() {
        this.drawnStep && this.drawnStep.update();
    }

    exportDrawnData() {
        return {};
    }

    /**
     * @param canvas {BaseCanvas}
     */
    onCanvasLoaded(canvas) {
    }

    onPainterLoaded(painter) {
    }

    /**
     * @param canvas {BaseCanvas}
     */
    setCanvas(canvas) {
        this.canvas = canvas;
        this.onCanvasLoaded(canvas);
    }

}